package com.maidada.mddaichat.service.impl;

import com.github.yulichang.query.MPJQueryWrapper;
import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.maidada.mddaichat.entity.AiInfo;
import com.maidada.mddaichat.entity.AiModel;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.maidada.mddaichat.entity.UserAiConfig;
import com.maidada.mddaichat.mapper.UserAiConfigMapper;
import com.maidada.mddaichat.service.UserAiConfigService;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * [用户ai配置]服务实现类
 *
 * @author wulinxuan
 * @date 2025-04-17 17:43
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class UserAiConfigServiceImpl extends ServiceImpl<UserAiConfigMapper, UserAiConfig>
    implements UserAiConfigService {

    private final UserAiConfigMapper userAiConfigMapper;

    @Override
    public UserAiConfig queryUserConfig(String userId, String model) {
        MPJLambdaWrapper<UserAiConfig> wrapper = JoinWrappers.lambda();

        // join
        wrapper.selectAll(UserAiConfig.class)
                .innerJoin(AiInfo.class, AiInfo::getId, UserAiConfig::getAiId)
                .innerJoin(AiModel.class, AiModel::getAiId, AiInfo::getId);

        // condition
        wrapper.eq(UserAiConfig::getUserId, userId)
                .eq(AiModel::getModelName, model);

        return userAiConfigMapper.selectOne(wrapper);
    }
}
